<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">用户称号</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>用户称号</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：
            <select id="userTitle-search-key">
                <option value="">-请选择-</option>
                <option value="ttname">称号名称</option>
                <option value="tpname">称号类型</option>
            </select>&emsp;
            <input id="userTitle-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="userTitle-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="userTitle-table" lay-filter="userTitle-table"></table>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="userTitle-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
</script>

<script>
    layui.use(['form', 'index', 'util', 'table', 'config'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var util = layui.util;
        var index = layui.index;

        var login_user = "";
        // 获取当前用户信息
        index.getUser(function (user) {
            login_user = user.id;
            console.log(login_user)
        });
        // 渲染表格
        table.render({
            elem: '#userTitle-table',
            // url: config.base_server + 'title_query.json',
            url: config.base_server + 'api-user/title/getTitleByUserId',
            method: 'post',
            where: {
                access_token: config.getToken().access_token,
                userId: login_user
            },
            page: true,
            cols: [[
                {type: 'numbers'},
                {field: 'ttname', sort: true, title: '称号名称'},
                {field: 'titleImgUrl', sort: true, title: '称号图片',
                    templet:function (data){
                        return '<img src="'+ data.titleImgUrl +'" width="30px" height="30px"></img>'
                    }},
                {field: 'tpname', sort: true, title: '称号类型'},
                {field: 'status', sort: true, title: '称号状态',
                    templet:function (data){
                    if (data.status == 1){
                        return '未用'
                    }else {
                        return '使用中'
                    }
                    }},
                {
                    sort: true, templet: function (d) {
                        return util.toDateString(d.cretim);
                    }, title: '获得时间'
                },
            ]]
        });

        // 搜索按钮点击事件
        $('#userTitle-btn-search').click(function () {
            var key = $('#userTitle-search-key').val();
            var value = $('#userTitle-search-value').val();
            table.reload('userTitle-table', {where: {searchKey: key, searchValue: value, userId: login_user}});
        });

    });
</script>